#pragma once

#include "QualifierValue.h"

#include "InputPin.h"
#include "Property.h"

namespace uml {

QualifierValue::QualifierValue(const QString& umlType)
    : Element(umlType) {}

void QualifierValue::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Element::fromJson(json, errorList);
    qualifier_ = JsonSerializable::create<Property>(json.value("qualifier"), errorList);

    value_ = JsonSerializable::create<InputPin>(json.value("value"), errorList);

}

void QualifierValue::toJson(QJsonObject& json) {
    Element::toJson(json);
    if (qualifier_) {
        QJsonObject qualifier_json;
        qualifier_->toJson(qualifier_json);
        json.insert("qualifier", qualifier_json);
    }
    if (value_) {
        QJsonObject value_json;
        value_->toJson(value_json);
        json.insert("value", value_json);
    }
}

/// <summary>
/// qualifier getter
/// The qualifier Property for which the value is to be specified.
/// </summary>
shared_ptr<Property> QualifierValue::qualifier() const {
    return qualifier_;
}

/// <summary>
/// qualifier setter
/// The qualifier Property for which the value is to be specified.
/// </summary>
void QualifierValue::setQualifier(shared_ptr<Property> value) {
    qualifier_ = value;
}

/// <summary>
/// value getter
/// The InputPin from which the specified value for the qualifier is taken.
/// </summary>
shared_ptr<InputPin> QualifierValue::value() const {
    return value_;
}

/// <summary>
/// value setter
/// The InputPin from which the specified value for the qualifier is taken.
/// </summary>
void QualifierValue::setValue(shared_ptr<InputPin> value) {
    value_ = value;
}

} // namespace uml
